<?php

namespace app\admin\model;

use think\Model;

/**
 * 需求
 * @package app\admin\model
 */
class RequirementsForm extends Model
{
    /**
     * 需求总数
     * @param array $where
     * @return int
     */
    public static function countRequirementsForm($where = [])
    {
        return self::where($where)
            ->where('status', '<>', -1)
            ->count();
    }

    /**
     * 当日新增需求
     * @return int
     */
    public static function todayRequirementsForm()
    {
        return self::whereDay('create_time')
            ->where('status', '<>', -1)
            ->count();
    }

    /**
     * 需求分类
     * @return array
     */
    public static function requirementsFormCate()
    {
        $data = self::alias('f')
            ->fieldRaw("COUNT(f.cids) nums,f.cids,c.name,c.color")
            ->join('resource_cate c', 'f.cids = c.id', 'left')
            ->where([
                ['f.status', '<>', -1],
                ['f.cids', '>', 0],
            ])
            ->group('f.cids')
            ->select();
        return $data ? $data->toArray() : [];
    }

}